<?php
header("Content-Type:text/html; charset=utf-8");
include_once('../inc/init.php');
include_once('../inc/cache.php');
include_once('inc/adminfun.php');
if(!isAdmin()){
	exit("请登录");
}

$action=strFilter($_GET['action']);
switch($action){
	case "install":
		try{
			$templates=array();
			$tkeys=$_POST['tkeys'];
			$tdefault=$_POST['tdefault'];
			$tname=$_POST['tname'];
			$torder=$_POST['torder'];
			$color1=$_POST['color1'];
			
			if(is_array($tname)) {
				$row=array();
				foreach($tname as $styleid => $value) {
					if(empty($tkeys) || (!in_array($styleid,$tkeys)&&$tdefault!=$styleid)){
						continue;
					}
					$row['id']=$styleid;
					$row['name']=$value;
					$row['color1']=$color1[$styleid];
					$row['order']=$torder[$styleid];
					$row['default']=$tdefault;
					$templates[$styleid]=$row;
				}
			}

			foreach ($templates as $key => $value) {
				$ordernum[$key] = $value['order'];
			}
			@array_multisort($ordernum, $templates);
			//$templates['default']=$tdefault;
			$str="<?php\r\n";
			$str.="\$cache_template = ".varToStr($templates)."; \r\n";
			$str.="?>";
			writeFile(getCacheFilePath("template.php"),$str);
			echo("y");
		}catch(Exception $e){
			echo($e);
		}
	break;

	default:
		echo"No Such Action";
	break;
}
?>